package pl.un4giv3n.mightvsmagic.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@NamedQueries({
	@NamedQuery(name="find.all.messages.by.senderId", query="select m from Message m where m.senderId = :senderId"),
	@NamedQuery(name="find.recent.messages.by.senderId", query="select m from Message m where m.senderId = :senderId and m.sendTime > :sendTime"),
	@NamedQuery(name="find.all.messages.by.reciverId", query="select m from Message m where m.reciverId = :reciverId"),
	@NamedQuery(name="find.recent.messages.by.reciverId", query="select m from Message m where m.reciverId = :reciverId and m.sendTime > :sendTime"),
	@NamedQuery(name="find.recent.unread.messages.by.reciverId", query="select m from Message m where m.reciverId = :reciverId and m.sendTime > :sendTime and m.reciverRead = false")
})
@Entity
public class Message {

	private Long id;
	private long senderId;
	private long reciverId;
	
	private String senderName;
	private String reciverName;
	private String message;
	private String subject;
	
	private boolean reciverRead;
	private long sendTime;
	
	public Message(){
	}
	
	public Message(String subject, String message, User sender, User reciver){
		this.subject = subject;
		this.message = message;
		this.senderId = sender.getId();
		this.senderName = sender.getLogin();
		this.reciverId = reciver.getId();
		this.reciverName = reciver.getLogin();
		this.sendTime = System.currentTimeMillis();
	}
	
	public String getSenderName() {
		return senderName;
	}
	public void setSenderName(String senderName) {
		this.senderName = senderName;
	}
	public String getReciverName() {
		return reciverName;
	}
	public void setReciverName(String reciverName) {
		this.reciverName = reciverName;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}
	
	void setId(Long id) {
		this.id = id;
	}
	public boolean isReciverRead() {
		return reciverRead;
	}
	public void setReciverRead(boolean reciverRead) {
		this.reciverRead = reciverRead;
	}
	public long getSendTime() {
		return sendTime;
	}
	public void setSendTime(long sendTime) {
		this.sendTime = sendTime;
	}

	public void setSenderId(long senderId) {
		this.senderId = senderId;
	}

	public void setReciverId(long reciverId) {
		this.reciverId = reciverId;
	}

	public long getSenderId() {
		return senderId;
	}

	public long getReciverId() {
		return reciverId;
	}
	
}
